/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bluelinelabs.conductor.conductor.view;

import com.bluelinelabs.conductor.conductor.ResourceTable;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.DependentLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.dialog.BaseDialog;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;
import ohos.utils.net.Uri;


/**
 * lipeiquan
 *
 * @since 2021-05-06
 */
public class AboutDialogView extends CommonDialog implements BaseDialog.DialogListener {

    public AboutDialogView(Context context) {
        super(context);
        init(context);
        setTransparent(true);
        setDialogListener(this);
    }


    private void init(Context context) {

        DependentLayout toastLayout = (DependentLayout) LayoutScatter.getInstance(context)
            .parse(ResourceTable.Layout_view_about, null, false);
        setContentCustomComponent(toastLayout);
        toastLayout.findComponentById(ResourceTable.Id_correct).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                destroy();
            }
        });
        toastLayout.findComponentById(ResourceTable.Id_web).setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri uri = Uri.parse("https://gitee.com/chinasoft_ohos/Conductor");
                intent.setUri(uri);
                component.getContext().startAbility(intent,1);
            }
        });

    }


    @Override
    public boolean isTouchOutside() {
        destroy();
        return false;
    }
}
